define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shop/withdraw/index' + location.search,
                    add_url: 'shop/withdraw/add',
                    edit_url: 'shop/withdraw/edit',
                    del_url: 'shop/withdraw/del',
                    multi_url: 'shop/withdraw/multi',
                    import_url: 'shop/withdraw/import',
                    table: 'shop_withdraw',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                singleSelect:true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'shop_id', title: __('Shop_id'),operate:false},
                        {field: 'shop.name', title: __('店铺名称'), operate: 'LIKE',align:'left'},
                        {field: 'user.mobile', title: __('手机号'), operate: 'LIKE'},
                        {field: 'type', title: __('扣款类型'), searchList:{"0":"全平台扣点","1":"店铺月抽佣","2":"sim卡扣月费"},formatter: function (value, row, index) {
                                if(value === 0){
                                    return '<span style="background-color: #1688f1;padding: 3px 9px;border-radius: 5px;color: #FFFFFF">全平台扣点</span>';
                                }else if(value === 1){
                                    return '<span style="background-color:#eb9316;padding: 3px 9px;border-radius: 5px;color: #FFFFFF">店铺月抽佣</span>';
                                }else{
                                    return '<span style="background-color: #f98175;padding: 3px 9px;border-radius: 5px;color: #FFFFFF">sim卡扣月费</span>';
                                }
                            }},
                        {field: 'amount', title: __('Amount'), operate:false},
                        {field: 'remark', title: __('Remark'), operate: false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });



            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
